<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>核算</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="/css/modules.css" type="text/css"	media="screen" />
	<link rel="stylesheet" href="/css/modules1.css" type="text/css"	media="screen" />
	<link rel="stylesheet" href="/css/jquery-ui.css" type="text/css"	media="screen" />
	<link rel="stylesheet" href="/css/jquery.wysiwyg.css" type="text/css"	media="screen" />
	<style type="text/css">
		label{
			display:inline;
		}
		.input-medium{
			width:180px;
		}
	</style>
	<script type='text/javascript' src="/js/jquery-1.4.2.min.js"></script>	
	<script type='text/javascript' src="/js/jquery.js"></script>
	<script type='text/javascript' src="/js/jquery-ui.js"></script>
	<script type='text/javascript' src="/js/jquery.wysiwyg.js"></script>
	<script type='text/javascript' src="/js/custom.js"></script>
	<script type='text/javascript'>
	Date.prototype.format = function(format)
{
    var o =
    {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format))
    format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
    if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}
	</script>
	<script type='text/javascript'>
	var dd=new Date();
	var day_first_day=new Date(dd-86400000).format("yyyy-MM-dd");
	var week_first_day=new Date(dd-dd.getDay()*86400000-86400000*7).format("yyyy-MM-dd");
	var week_last_day=new Date((new Date(dd-dd.getDay()*86400000-86400000*7)/1000+6*86400)*1000).format("yyyy-MM-dd");
	var month_first_day=new Date(dd.getFullYear(),dd.getMonth()-1,1).format("yyyy-MM-dd");
	var month_last_day=new Date(new Date(dd.getFullYear(),dd.getMonth(),1)-86400000).format("yyyy-MM-dd");
	var year_first_day=new Date(dd.getFullYear()-1,0,1).format("yyyy-MM-dd");
	var year_last_day=new Date(new Date(dd.getFullYear(),0,1)-86400000).format("yyyy-MM-dd");
		$(function(){
			$("#query_date").change(function(){
				var st,et;
				if($(this).val()=="DAY"){
					st=day_first_day;et=day_first_day;
				}else if($(this).val()=="WEEK"){
					st=week_first_day;et=week_last_day;
				}else if($(this).val()=="MONTH"){
					st=month_first_day;et=month_last_day;
				}else if($(this).val()=="YEAR"){
					st=year_first_day;et=year_last_day;
				}else{
					st=day_first_day;et=day_first_day;
				}
		//		$("#startTimeLabel").html(st);
			//	$("#endTimeLabel").html("至"+et);
				$("input[name='startTime']").val(st);
				$("input[name='endTime']").val(et);
			});
		});
	
		var url;
		var dialogOption={height: 300,width:880,modal:true,position: [0,50]};
		function addPro(){
			jQuery("#addProduct").dialog(dialogOption);
			jQuery("#addProduct").dialog("open");
		}
		function findRecordByPid(pid){
			url="/RecordAction!findRecord.action?product.id="+pid;
			$("#getRecord").load(url,function(){
				jQuery("#getRecord").dialog();
				jQuery("#getRecord").dialog("open");
			});
			
		}
		function purchase(operate,pid){
			url="/ProductAction!getProduct.action?productid="+pid+"&operate="+operate;
			$("#purchase").load(url,function(){
				jQuery("#purchase").dialog();
				jQuery("#purchase").dialog("open");
			});
		}
		
		function editProduct(pid){
			url="/ProductAction!edit.action?productid="+pid;
			$("#editProduct form").load(url,function(){
				jQuery("#editProduct").dialog(dialogOption);
				jQuery("#editProduct").dialog("open");
			});
		}
		
			function loadCity(f){
			var provinceid=$(f).val();
			$("#cityspan").load("/area/province!getCity.action?provinceid='"+provinceid+"'");
			$("#regionspan").html("");
			$(f).attr("name","provinceid");
		//	$("#psel").attr("name","ff.dd");
		}
		
		function loadRegion(f){
			var cityid=$(f).val();
			$("#regionspan").load("/area/province!getRegion.action?cityid='"+cityid+"'");
			$("#psel").attr("name","");
			$(f).attr("name","provinceid");
		//	$("#csel").attr("name","");
		}

		function zz(f){
			
			$("#csel").attr("name","");
			$(f).attr("name","provinceid");
		//	$("#csel").attr("name","");
		}
		
		function validate(form){
			var flag=false;
			if($("#areaSelect .select:eq(0)").val()!=0){
				flag=true;
			}else{
				alert("请选择查询区域!");
			}
			return flag;
		}
	</script>
	
  </head>
  
<body style="background-color:transparent">
	<!--  Goods_list header -->
	<div>
  		<h2 class="jquery_tab_title">
  			<s:if test="#session.user.role.name=='销售经理'||#session.user.role.name=='营销总监'">
  				<s:iterator value="#session.user.provinces">
  					核算——<s:property value="name" />——昨日  <s:date name="queryDate" format="yyyy-MM-dd" />
  				</s:iterator>
  			</s:if>
  			<s:else>核算——<s:if test="areaName!=null">${areaName}</s:if><s:else>全国</s:else>——<s:if test="startTime!=null"><s:date name="startTime" format="yyyy-MM-dd" />~ <s:date name="endTime" format="yyyy-MM-dd" /></s:if><s:else>昨日 <s:date name="queryDate" format="yyyy-MM-dd" /></s:else></s:else>
  		</h2>
  	</div>
  	<!--  Goods_list  -->
  	<div>
  		<form action="/AccountAction!query.action" method="post" onsubmit="return validate(this);">
  			<table id="noborder_table">
				<tr>
					<td id="areaSelect">
						<s:if test="#session.user.role.name=='销售经理'">
							<span id="regionspan">
								<s:select  list="%{provinceList}" listKey="id" listValue="name"	theme="simple" 
								cssClass="select" headerValue="请选择" headerKey="0"></s:select>
						 	</span>
						</s:if>
						<s:elseif test="#session.user.role.name=='营销总监'">
							<span id="cityspan">
								<s:select id="csel" list="%{provinceList}" listKey="id" listValue="name" theme="simple" 
								cssClass="select" onchange="loadRegion(this);" headerValue="请选择" headerKey="0"  >
								</s:select>
							</span>
							<span id="regionspan"> </span>
						</s:elseif>
						<s:else>
						<span id="provincespan">
							<s:select id="psel" list="%{provinceList}" listKey="id" listValue="name"
	theme="simple" cssClass="select" onchange="loadCity(this);"
	headerValue="请选择区域" headerKey="0"></s:select>
							 </span>
							<span id="cityspan"> </span>
							<span id="regionspan"> </span>
						</s:else>
						</td>
						<td>
							<select id="query_date" name="dateType">
								<option value="DAY">请选择时间</option>
								<option value="DAY">昨天</option>
								<option value="WEEK">上周</option>
								<option value="MONTH">上个月</option>
								<option value="YEAR">去年</option>
							</select>
						</td>
						<td>
						<label id="startTimeLabel"></label>
						<label id="endTimeLabel"></label>
						</td>
						<td>
							<input type="hidden" name="type" value="PURCHASE"/>
							<input type="submit" class="button" value="查询" />
						</td>
					</tr>
				</table></form>
  		<table cellspadding="0" cellspacing="0" width="100%">
  			<tr>
  			<th class="th_first">商品名称</th>
  			<th>商品编号</th>
  			<th>进货数量</th>
  			<th>时间</th></tr>
  			<s:iterator value="accounts">
  			<tr>
				<td class="td_first">${product.name }</td>
				<td>${product.code }</td>
				<td>${quantity }</td>
				<td><s:date name="date" format="yyyy/MM/dd" /></td>
			</tr>
			</s:iterator>
  		</table>
  	
  	</div>
  	
   	<div style="padding:10px;">
   		<span style="float:left">
   		<!-- 
   			<input type="button" value="选中全部" class="button" />
   			<input type="button" value="批量删除" class="button"/>
   		 -->
   			
   		</span>
   		<span style="float:right">
   			${pagination }
   		</span>
   	</div>
  </body>
</html>
